package org.myOrg.spetrum.GUI;

import java.awt.BorderLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;

class ShowPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected JLabel label;
	private JTextPane textPane;
	protected DefaultStyledDocument doc;

	public ShowPanel() {
		build();
	}

	private void build() {
		label = new JLabel("");
		doc = new DefaultStyledDocument();
		textPane = new JTextPane(doc);
		textPane.setEditable(false);
		JScrollPane scrollPane = new JScrollPane(textPane);
		this.setLayout(new BorderLayout());
		this.add(label, BorderLayout.SOUTH);
		this.add(scrollPane, BorderLayout.CENTER);
	}
	
	public void insertOneLine(String string ,AttributeSet style){
		try {
			doc.insertString(doc.getLength(), string+"\r\n", style);
		} catch (BadLocationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void insertString(String string ,AttributeSet style){
		try {
			doc.insertString(doc.getLength(), string, style);
		} catch (BadLocationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void clear(){
		try {
			doc.remove(0, doc.getLength());
			label.setText("");
		} catch (BadLocationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void setLabelString(String str) {
		label.setText(str);
	}

}